/**
 * @author hanzc
 * @date 2021-01-29
 */
import {downloadBlob} from '~/utils/common/download';
import http from './http';
import constant from './constant';

// 查询select选项
export const querySelectOptions = params =>
    http.post(constant.REFUND_REPORT.QUERY_SELECT_OPTIONS, params);

// 查询dashboard数据, 包括card和chart
export const queryValues = params =>
    http.post(constant.REFUND_REPORT.QUERY_VALUES, params);

// 查询card和chart的详情
export const queryDetail = params =>
    http.post(constant.REFUND_REPORT.QUERY_DETAIL, params);

// 下载card和chart
export const download = (params = {}, excelName = '', callback) => {
    http({
        url: constant.REFUND_REPORT.DOWNLOAD,
        method: 'post',
        data: {
            ...params
        },
        responseType: 'blob'
    })
        .then(res => {
            const blob = new Blob([res], {
                type: 'application/vnd.ms-excel;'
            });
            const time = new Date().getTime();
            const name = `${excelName}${time}.xlsx`;
            downloadBlob(blob, name);
        })
        .finally(() => {
            typeof callback === 'function' && callback();
        });
};

// 中心评分表
// 定制表格接口
export const queryCentralTable = params =>
    http.post(constant.REFUND_REPORT.CENTRAL_TABLE, params);
// 查询select选项
export const querySelectOptions1 = params =>
    http.post(constant.REFUND_REPORT.QUERY_SELECT_OPTIONS_1, params);
// 查询dashboard数据, 包括card和chart
export const queryCentralValues = params =>
    http.post(constant.REFUND_REPORT.QUERY_CENTRAL_VALUES, params);

// 春季续班 - 概览 - 综合续班率进度
export const fetchData = param => http.post('/api/springContinuation/overview/values', {
    ...param
});
// 春季续班定制化接口
export const querySpringValues = params =>
    http.post(constant.STRING_XU_BAN.QUERY_VALUES, params);

export const querySpringExcelValues = params =>
    http.post(constant.STRING_XU_BAN.QUERY_EXCEL_VALUES, params);

export const querySpringPercentage = params =>
    http.post(constant.STRING_XU_BAN.QUERY_EXCEL_PERCENT_VALUES, params);

export const queryCarouselMessage = params =>
    http.post(constant.STRING_XU_BAN.CAROUSEL_MESSAGE, params);
